55B - Smallest number - CodeForces Solution


brute force *1600

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long

ll a, b, c, d;
char t[10];

ll ans = 1e18;
void root(ll a,ll b) {
    ll x = (t[4] == '+') ? (a + b) : (a * b);
    if (ans > x) {
        ans = x;
    }
}
void branch(ll a,ll b,ll c) {
    if (t[3] == '+') {
        root(a + b, c);
        root(a + c, b);
        root(b + c, a);
    } else {
        root(a * b, c);
        root(a * c, b);
        root(b * c, a);
    }
}
void mainbranch(ll a,ll b,ll c,ll d) {
    if (t[2] == '+') {
        branch(a + b, c, d);
        branch(a + c, b, d);
        branch(a + d, b, c);
        branch(b + c, a, d);
        branch(b + d, a, c);
        branch(c + d, a, b);
    } else {
        branch(a * b, c, d);
        branch(a * c, b, d);
        branch(a * d, b, c);
        branch(b * c, a, d);
        branch(b * d, a, c);
        branch(c * d, a, b);
    }
}

int main() {
    cin >> a >> b >> c >> d;
    for(int i = 2; i <= 4; i++)
        cin >> t[i];
    mainbranch(a, b, c, d);
    cout << ans << endl;
}
  					 		     	 	  		  	 	 	


Comments

Submit
1 Comments
  • 27/2/2023 16:34 - America/New_York

1 4 7 12 14 24 36 48


More Questions

489B - BerSU Ball
977C - Less or Equal
1505C - Fibonacci Words
1660A - Vasya and Coins
1660E - Matrix and Shifts
1293B - JOE is on TV
1584A - Mathematical Addition
1660B - Vlad and Candies
1472C - Long Jumps
1293D - Aroma's Search
918A - Eleven
1237A - Balanced Rating Changes
1616A - Integer Diversity
1627B - Not Sitting
1663C - Pōja Verdon
1497A - Meximization
1633B - Minority
688B - Lovely Palindromes
66B - Petya and Countryside
1557B - Moamen and k-subarrays
540A - Combination Lock
1553C - Penalty
1474E - What Is It
1335B - Construct the String
1004B - Sonya and Exhibition
1397A - Juggling Letters
985C - Liebig's Barrels
115A - Party
746B - Decoding
1424G - Years